package com.practices2.util.http.data;

import java.io.InputStream;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;

public class XMLPullParse {

////	/*
////	 * <response> <sessionid>111111</sessionid> <list> <note>
////	 * <note_guid>标识码GUID：32位字符串</note_guid>
////	 * <note_state>12覆盖上传，13删除，14覆盖下载、15新建下载（修改冲突）16修改冲突上传</note_state>
////	 * <note_version>版本：同步控制</note_version> <note_updated>更新时间：秒</note_updated>
////	 * <note_sort>类型：0混合型、1纯手写、2纯涂鸦</note_ sort > <create_console>0手机、1PC、2web
////	 * </ create_console > <attr> <attr_created></attr_created>
////	 * <attr_state>//覆盖下载时，需要告诉客户端哪些需要新建下载，哪些需要覆盖下载，哪些需要删除
////	 * 笔记属性状态:15新建下载、14覆盖下载（直接覆盖）、13删除 </attr_state>
////	 * <attr_type>文件_类型,涂鸦</attr_type> <attr_guid>笔记属性标识（文件名）</attr_ guid >
////	 * <data_len>验证文件是否完整，文字时为0</ data_len > <attr_content>文字字符串</attr_ content
////	 * > </attr> </note> </list> </response>
////	 */
////	public static String readXmlResponse_requestSyncronize(InputStream inputStream, List<NoteInfo> notes) {
////		String sessionid = null;
////		XmlPullParser parser = Xml.newPullParser();
////		try {
////			parser.setInput(inputStream, "UTF-8");
////			int eventType = parser.getEventType();
//////
//////			NoteInfo currentNote = null;
//////			NoteAttribute currentAttr = null;
////
////			while (eventType != XmlPullParser.END_DOCUMENT) {
////				switch (eventType) {
////				case XmlPullParser.START_DOCUMENT:// 文档开始事件,可以进行数据初始化处理
////					break;
////				case XmlPullParser.START_TAG:// 开始元素事件
////					String name = parser.getName();
////					if (name.equalsIgnoreCase(NetDefines.TAG_NOTE)) {
////						currentNote = new NoteInfo();
////						currentNote.initAttributes();
////					} else if (currentNote != null) {
////						if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_GUID)) {
////							currentNote.guid = (parser.nextText());// 如果后面是Text节点,即返回它的值
////						} else if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_STATE)) {
////							currentNote.state = (new Integer(parser.nextText()));
////						} else if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_VERSION)) {
////							currentNote.version = (new Integer(parser.nextText()));
////						} else if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_UPDATED)) {
////							currentNote.updated = (new Long(parser.nextText()));
////						} else if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_CREATED)) {
////							currentNote.created = (new Long(parser.nextText()));
////						} else if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_SORT)) {
////							currentNote.sort = (new Integer(parser.nextText()));
////						} else if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_CREATE_CONSOLE)) {
////							currentNote.create_console = (new Integer(parser.nextText()));
////						} else if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_ATTR)) {
////							currentAttr = new NoteAttribute();
////						} else if (currentAttr != null) {
////							if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_ATTR_CREATED)) {
////								currentAttr.created = new Long(parser.nextText());
////							} else if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_ATTR_GUID)) {
////								currentAttr.attrGuid = parser.nextText();
////							} else if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_ATTR_STATE)) {
////								currentAttr.state = new Integer(parser.nextText());
////							} else if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_ATTR_TYPE)) {
////								currentAttr.type = new Integer(parser.nextText());
////								if (currentAttr.type != NoteAttribute.TYPE_TEXT_CONTENT) {
////									currentAttr.newExtraInfoForDownload();
////								}
////							} else if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_ATTR_DATA_LEN)) {
////								currentAttr.setDataLenExtra(new Integer(parser.nextText()));
////							} else if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_ATTR_CONTENT)) {
////								if (currentAttr.type == NoteAttribute.TYPE_TEXT_CONTENT) {
////									currentAttr.setValue(parser.nextText());
////								} else {
////									currentAttr.setDataUrlExtra(parser.nextText());
////								}
////							} else if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_ATTR_THUMB_LEN)) {
////								currentAttr.setThumbLenExtra(new Integer(parser.nextText()));
////							} else if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_ATTR_THUME_NAME)) {
////								currentAttr.setThumbUrlExtra(parser.nextText());
////							}
////						}
////					} else if (name.equalsIgnoreCase(NetDefines.TAG_SESSION_ID)) {
////						sessionid = parser.nextText();
////					}
////					break;
////				case XmlPullParser.END_TAG:// 结束元素事件
////					String endTagName = parser.getName();
////					if (endTagName.equalsIgnoreCase(NetDefines.TAG_NOTE)) {
////						if (currentNote != null) {
////							notes.add(currentNote);
//////							if (U.debugFlag) {
//////								U.dout("[XmlProcessing]readXmlResponse_requestSyncronize currentNote.guid=" + currentNote.guid);
//////							}
////							currentNote = null;
////						} else {
//////							if (U.debugFlag) {
//////								U.dout("[XmlProcessing]readXmlResponse_requestSyncronize currentNote.guid222= null");
//////							}
////						}
////					} else if (endTagName.equalsIgnoreCase(NetDefines.TAG_NOTE_ATTR)) {
////						if (currentAttr != null) {
////							if (currentNote != null) {
////								currentNote.addAttribute(currentAttr);
////							}
////							currentAttr = null;
////						}
////					}
////					break;
////				}
////				eventType = parser.next();
////			}
////		} catch (Exception e) {
////			e.printStackTrace();
//////			if (U.debugFlag) {
//////				U.dout("[XmlProcessing]readXmlResponse_requestSyncronize Exception:" + e.getLocalizedMessage());
//////			}
////		}
////		return sessionid;
////	}
//
//	/*
//	 * 返回guid
//	 * 
//	 * <response> <note_guid>034234123412342</note_guid> </response>
//	 */
//	public static String readXmlResponse_requestUploadNote(InputStream is) {
//		XmlPullParser parser = Xml.newPullParser();
//		
//		String guid = null;
//		try {
//			parser.setInput(is, "UTF-8");
//			int eventType = parser.getEventType();
//
//			while (eventType != XmlPullParser.END_DOCUMENT) {
//				switch (eventType) {
//				case XmlPullParser.START_DOCUMENT:// 文档开始事件,可以进行数据初始化处理
//					break;
//				case XmlPullParser.START_TAG:// 开始元素事件
//					String name = parser.getName();
//					if (name.equalsIgnoreCase(NetDefines.TAG_NOTE_GUID)) {
//						guid = parser.nextText();
//						return guid;
//					} else if (name.equalsIgnoreCase(NetDefines.TAG_RESULT)) {
////						if (U.debugFlag) {
////							U.dout("[XmlProcessing]readXmlResponse_requestUploadNote Result:" + parser.nextText());
////						}
//					}
//					break;
//				case XmlPullParser.END_TAG:// 结束元素事件
//					break;
//				}
//				eventType = parser.next();
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
////			if (U.debugFlag) {
////				U.dout("[XmlProcessing]readXmlResponse_requestUploadNote Exception!!!");
////			}
//		}
//		return guid;
//	}
//
//	/*
//	 * 返回session id
//	 * 
//	 * <response> <sessionId>21343242341234</sessionId> </response>
//	 */
//	public static String readXmlResponse_requestSessionId(InputStream is) {
//		XmlPullParser parser = Xml.newPullParser();
//		String sessionId = null;
//		try {
//			parser.setInput(is, "UTF-8");
//			int eventType = parser.getEventType();
//
//			while (eventType != XmlPullParser.END_DOCUMENT) {
//				switch (eventType) {
//				case XmlPullParser.START_DOCUMENT:// 文档开始事件,可以进行数据初始化处理
//					break;
//				case XmlPullParser.START_TAG:// 开始元素事件
//					String name = parser.getName();
//					if (name.equalsIgnoreCase(NetDefines.TAR_SESSION)) {
//						sessionId = parser.nextText();
//						return sessionId;
//					} else if (name.equalsIgnoreCase(NetDefines.TAG_RESULT)) {
////						if (U.debugFlag) {
////							U.dout("[XmlProcessing]readXmlResponse_requestSessionId Result:" + parser.nextText());
////						}
//					}
//					break;
//				case XmlPullParser.END_TAG:// 结束元素事件
//					break;
//				}
//				eventType = parser.next();
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
////			if (U.debugFlag) {
////				U.dout("[XmlProcessing]readXmlResponse_requestSessionId Exception!!!");
////			}
//		}
//		return sessionId;
//	}
//
//	/*
//	 * <response> <result>0.2% 44M/140800M</result> </response>
//	 */
//	public static String readXmlResponse_ForResult(InputStream is) {
//		XmlPullParser parser = Xml.newPullParser();
//		String ret = null;
//		try {
//			parser.setInput(is, "UTF-8");
//			int eventType = parser.getEventType();
//
//			while (eventType != XmlPullParser.END_DOCUMENT) {
//				switch (eventType) {
//				case XmlPullParser.START_DOCUMENT:// 文档开始事件,可以进行数据初始化处理
//					break;
//				case XmlPullParser.START_TAG:// 开始元素事件
//					String name = parser.getName();
////					if (U.debugFlag) {
////						U.dout("[XmlProcessing]readXmlResponse_requestUploadNote name=" + name);
////					}
//					if (name.equalsIgnoreCase(NetDefines.TAG_RESULT)) {
//						ret = parser.nextText();
////						if (U.debugFlag) {
////							U.dout("[XmlProcessing]readXmlResponse_requestUploadNote ret111=" + ret);
////						}
//						return ret;
//					}
//					break;
//				case XmlPullParser.END_TAG:// 结束元素事件
//					break;
//				}
//				eventType = parser.next();
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
////			if (U.debugFlag) {
////				U.dout("[XmlProcessing]readXmlResponse_requestUploadNote Exception!!!");
////			}
////		}
////		if (U.debugFlag) {
////			U.dout("[XmlProcessing]readXmlResponse_requestUploadNote ret222=" + ret);
////		}
//		return ret;
//	}
//
//	public static String createTag(String name, String value, String attribute) {
//		return "<" + name + " " + attribute + ">" + value + "</" + name + ">";
//	}
//
//	public static String createTag(String name, String value) {
//		return "<" + name + ">" + value + "</" + name + ">";
//	}
//
//	public static String createTagByCData(String name, String value) {
//		return "<" + name + "><![CDATA[" + value + "]]></" + name + ">";
//	}
//
//	/*
//	 * 上传需要同步的笔记信息
//	 */
//	// public static String makeupXml_requestUploadOrDeleteNotes(String
//	// notesXml, String finalValue) {
//	// notesXml = XmlProcessing.createTag(NetDefines.TAG_LIST, notesXml);
//	// String finishTag = XmlProcessing.createTag(NetDefines.TAG_FINAL,
//	// finalValue);
//	// return XmlProcessing.createTag(NetDefines.TAG_REQUEST, notesXml +
//	// finishTag, NetDefines.API_VERSION);
//	// }
//
//	// public static String getFinalTagWithValue() {
//	// return NetDefines.TAG_FINAL_WITH_VALUE;
//	// }

}
